/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.adama.repository;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.MassIndexer;
import org.hibernate.search.Search;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author avisto
 */
@Repository
public class RebuiltIndex {

    @Autowired
    SessionFactory sessionFactory;

    public void rebuiltIndex() throws InterruptedException {

        Session currentSession = sessionFactory.openSession();
        
        
        FullTextSession fullTextSession = Search.getFullTextSession(currentSession);
        MassIndexer mass=fullTextSession.createIndexer()
                .purgeAllOnStart(true) // true by default, highly recommended

                .optimizeAfterPurge(true) // true is default, saves some disk space

                .optimizeOnFinish(true); // true by default

               mass.start();
     

    }
}
